package com.example.JPetStore.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.JPetStore.Common;
import com.example.JPetStore.domain.Address;
import com.example.JPetStore.domain.Order;
import com.example.JPetStore.domain.User;
import com.example.JPetStore.mappers.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Service
public class OrderDao {

    @Autowired
    private OrderMapper orderMapper;


    public void addOrder(Order order) {
        orderMapper.insert(order);
    }
    //查询所有订单
    public ArrayList<Order> queryOrders(User user) {
        List<Order> orderList=orderMapper.selectList((new QueryWrapper<Order>()).eq("user_id", user.getUserId()));
        ArrayList<Order> orderArrayList=new ArrayList<>(orderList);
        return orderArrayList;
    }
    public Order queryOrderById(User user, String orderId) {
        Order order=orderMapper.selectOne((new QueryWrapper<Order>()).eq("user_id", user.getUserId()).eq("order_id",orderId));
        return order;
    }
}
